package com.mkait.thief.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PHPSessionUtils {
    /**
     * 获取商户用户名
     * @param session
     * @return
     */
    public static String getUserName(String session) {
        return null;
    }

    /**
     * 获取商户用户id
     * @param session
     * @return
     */
    public static String getUserId(String session) {
        Pattern p = Pattern.compile("(s:4:\"user\";i:)([0-9]+)(;)");
        Matcher m = p.matcher(session);
        if (m.find()){
            String group = m.group(2);
            return group;
        }else {
            return null;
        }
    }

    /**
     * 判断用户权限 0-管理员 1-商户 2-游客
     * @param session
     * @return
     */
    public static int getUserType(String session) {
        Pattern p1 = Pattern.compile("s:2:\"id\";i:10000;");
        Matcher m1 = p1.matcher(session);
        if (m1.find()){
            return 0;
        }else{
            Pattern p = Pattern.compile("s:8:\"merchant\";");
            Matcher m = p.matcher(session);
            if (m.find()){
                return 1;
            }
        }
        return 2;
    }



}
